package cn.net.shuxing.yifu.common.quartz.trigger;

import cn.net.shuxing.yifu.common.util.LocalDateTimeUtil;
import cn.net.shuxing.yifu.common.util.RedisKeyCreator;
import org.quartz.*;

import java.time.LocalDateTime;
import java.util.Date;

public class UserActiveTriggerBuilder {

    public static Trigger build(LocalDateTime activateTime, JobDetail userActivateJobDetail)
    {
        SimpleScheduleBuilder userActiveJobTrigger = SimpleScheduleBuilder.simpleSchedule();
        LocalDateTime activateDateTime = LocalDateTime.now();
        activateDateTime = activateDateTime.plusYears(activateTime.getYear())
                        .plusMonths(activateTime.getMonthValue())
                        .plusDays(activateTime.getDayOfMonth())
                        .plusHours(activateTime.getHour())
                        .plusMinutes(activateTime.getMinute());
        Date activateDateTime1 = LocalDateTimeUtil.toDate(activateDateTime);
        return TriggerBuilder.newTrigger()
                .forJob(userActivateJobDetail)//关联上述的JobDetail
                .withIdentity("userActiveJobTrigger")//给Trigger起个名字
                .withSchedule(userActiveJobTrigger)
                .startAt(activateDateTime1)
                .build();
    }
}
